<template>
	<view class="connect">
		<!-- <u-navbar :is-back="false" back-text=" " :title-color="style.color5" :background="{background:style.color2}" :title-size="30" :title-width="400" title="我的"></u-navbar> -->
		<view class="user_info" :style="{background: `linear-gradient( 116deg, ${style.color8} 0%,  ${style.color9} 100%)`}" >
			<!--  -->
			<view class="user_info_box" >
				<u-image width="120rpx" height="120rpx" shape="circle" :src="userInfo.pic?userInfo.pic:'../../static/inde_png/index_icon_19.png'"></u-image>
				<view class="user_info_box_left">
					<view class="" style="display: flex;">
						<view class="vip_box">
							<image style="width: 20rpx; height: 20rpx;margin-right: 5rpx;" src="../../static/icon/icon_5.png" mode=""></image>
							{{userInfo.user_grade.name?userInfo.user_grade.name:'大众会员'}}
						</view>
					</view>
					<view class="user_name " >{{userInfo.nickname}}</view>
					<span class="other_info">{{userInfo.code}}</span>
				</view>
			</view>
			<view class="self_bar_item" style="height: 150rpx; margin-bottom: 70rpx;">
				<view class="self_bar_item_box">
					<span class="fonr_800">{{userInfo.balance}}</span>
					<span class="fonr_800">余额</span>
				</view>
				<view  @click="navTo('/pages/point_list/point_list')" class="self_bar_item_box">
					<span class="fonr_800">{{userInfo.points}}</span>
					<span class="fonr_800">积分</span>
				</view>
				<view @click="navTo('/pages/follow/follow')" class="self_bar_item_box">
					<span class="fonr_800">0</span>
					<span class="fonr_800">收藏</span>
				</view>
			</view>
			<u-icon class="icon" @click="navTo('/pages/userInfo/userInfo')" name="setting" color="#000" size="50"></u-icon>
		</view>
		<view class="other_box">
			<!-- <view class="other_box_1">
				<view @click="navTo('/pages/userInfo/userInfo')" class="favorite " style="border-right: 1rpx solid #ccc;">
					<view class="favorite_left">
						<span class="favorite_title" >用戶信息</span>
					</view>
					<u-icon  name="arrow-right" color="#ccc" size="28"></u-icon>
				</view>
				<view @click="navTo('/pages/self/foot_list')" class="favorite">
					<view class="favorite_left">
						<span class="favorite_title">我的足迹</span>
					</view>
				<u-icon  name="arrow-right" color="#ccc" size="28"></u-icon>
				</view>
			</view> -->
			<view class="vip_te">
				<view class="vip_te_left">
					<image style="width: 24rpx; height: 24rpx;" src="../../static/icon/icon_5.png" mode=""></image>
					<span class="vip_te_left_1">会员特权</span>
					<span class="vip_te_left_2">会员晋升购物最高95折</span>
				</view>
				<view @click="navTo('/pages/self/vip')"  class="vip_te_right">
					查看权益
				</view>
			</view>
			
			<view class="order_tab1">
				<view class="order_tab1_box">
					<view class="order_tab_title">
						<span class="order_tab_title_1">普通订单</span>
						<span class="order_tab_title_2" @click="navTo('/pages/good_order_List/good_order_List?current=0')">
							查看全部订单
							<u-icon  name="arrow-right" color="#010101" size="24"></u-icon>
						</span>
					</view>
					<view class="order_tab_baritem">
						<view @click="navTo('/pages/good_order_List/good_order_List?current='+item.status)" v-for="(item,index) in barList" :key="index" class="bar_item">
							<image style="width: 60rpx; height: 60rpx; margin-bottom: 10rpx;" :src="item.icon" mode=""></image>
							
							<span class="bar_toast2">{{item.name}}</span>
							<view class="bar_toast" v-if="item.number_show && item.num>0">
								{{item.num}}
							</view>
						</view>
					</view>
				</view>
				
				<!-- <view class="order_tab_baritem">
					<view @click="navTo('/pages/good_order_List/good_order_List?current='+item.status)" v-for="(item,index) in barList" :key="index" class="bar_item">
						<image style="width: 60rpx; height: 60rpx;" :src="item.icon" mode=""></image>
						<span>{{item.name}}</span>
						<view class="bar_toast" v-if="item.number_show && item.num>0">
							{{item.num}}
						</view>
					</view>
				</view> -->
			</view>
			<!-- <view class="order_tab">
				<view class="order_tab_baritem">
					<view v-for="(item,index) in other_list" :key="index" @click="navTo(item.url)" class="bar_item2">
						<u-icon  :name="item.icon" color="#666" size="60"></u-icon>
						<span>{{item.name}}</span>
						<view class="bar_toast" v-if="item.number_show && item.num>0">
							{{item.num}}
						</view>
					</view>
				</view>
			</view> -->
			<view class="order_tab1">
				<view class="order_tab2">
					<view class="order_tab_baritem_title">
						常用功能
					</view>
					<view class="order_tab_baritem">
						
						<view v-for="(item,index) in other_list" :key="index" @click="navTo(item.url)" class="bar_item2">
							<u-icon  :name="item.icon" color="#666" size="60"></u-icon>
							<span class="bar_toast3">{{item.name}}</span>
							<view class="bar_toast" v-if="item.number_show && item.num>0">
								{{item.num}}
							</view>
						</view>
						<view class="bar_item2" @click="onlogOut">
							<u-icon  name="../../static/vip/icon_13.png" color="#666" size="60"></u-icon>
							<span class="bar_toast3">退出登录</span>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import config from "@/config/index.js";
	const {baseUrl , imgUrl} = config;
	export default {
		data() {
			return {
				style:{},
				navPadding:44,
				kor_type:'',
				type_choose:false,
				token:'',
				uid:null,
				barList:[
					{name:'待付款' , icon:'../../static/vip/icon_6.png' , status:1  , number_show:true ,num:0},
					{name:'待发货' , icon:'../../static/vip/icon_7.png' , status:2 , number_show:true ,num:0},
					{name:'已发货' , icon:'../../static/vip/icon_8.png' , status:3 , number_show:true ,num:0},
					{name:'已收货' , icon:'../../static/vip/icon_9.png' , status:4 , number_show:false ,num:0},
					{name:'退款中' , icon:'../../static/vip/icon_10.png' , status:7 , number_show:false ,num:0},
				],
				barList_buy:[
					{name:'待审核' , icon:imgUrl+'storage/self_icon/dai_shen_he.png' , status:0, number_show:true ,num:0},
					{name:'待支付' , icon:imgUrl+'storage/self_icon/dai_fu_kuan.png' , status:1, number_show:true ,num:0},
					{name:'待处理' , icon:imgUrl+'storage/self_icon/daiChuLi.png' , status:2, number_show:true ,num:0},
					{name:'已处理' , icon:imgUrl+'storage/self_icon/yicChuLi.png' , status:3, number_show:true ,num:0},
					{name:'已入库' , icon:imgUrl+'storage/self_icon/yiRuKu.png' , status:4, number_show:true ,num:0},
				],
				other_list:[
					{name:'用户信息' , icon:'../../static/vip/icon_14.png' , status:1 , url:'/pages/userInfo/userInfo',number_show:false,num:0},
					{name:'收货地址' , icon:'../../static/vip/icon_11.png' , status:1 , url:'/pages/address/address',number_show:false,num:0},
					{name:'我的足迹' , icon:'../../static/vip/icon_15.png' , status:1 , url:'/pages/self/foot_list',number_show:false,num:0},
					{name:'分销中心' , icon:'../../static/vip/icon_16.png' , status:1 , url:'/pages/self/distribution',number_show:false,num:0},
					{name:'优惠劵' , icon:'../../static/vip/icon_17.png' , status:1 , url:'/pages/coupon/coupon',number_show:true,num:0},
					// {name:'退出登录' , icon:'../../static/vip/icon_13.png' , status:1 , url:'/pages/follow/follow',number_show:false,num:0},
					// {name:'转寄' , icon:'storage/self_icon/zhuanJi.png' , status:1 , url:''},
				],
				userInfo:{
					nickname:'',
					code:''
				},
			}
		},
		onLoad(data) {
			const res = uni.getSystemInfoSync()
			this.navPadding = res.statusBarHeight+13
			if(data.uid){
				uni.setStorageSync('other_uid', data.uid)
			}
			// if(data.uid){
			// 	uni.setStorageSync('other_uid', data.uid)
			// 	// this.uid = uni.getStorageSync('other_uid')
			// 	this.uid = data.uid
			// 	if(this.uid){
			// 		this.token = uni.getStorageSync('token')
			// 		if(this.token ){
			// 			this.customer()
			// 		}
			// 	}
			// }
		},
		onShow() {
			this.token = uni.getStorageSync('token')
			this.kor_type = uni.getStorageSync('kor_type')?uni.getStorageSync('kor_type'):''
			this.type_choose = false
			var style =  uni.getStorageSync('style')
			style = JSON.parse(style)
			this.style = style
			if(this.token ){
				this.uid = uni.getStorageSync('other_uid')
				setTimeout(()=>{
					if(this.uid){
						this.token = uni.getStorageSync('token')
						if(this.token ){
							this.customer()
						}
					}
					if(this.kor_type == ''){
						this.type_choose = true
					}
				},500)
				this.getInfo()
			}else{
				
				if(this.kor_type == ''){
					this.type_choose = true
					return
				}	
				uni.setStorageSync('isModule' , true)
				uni.showModal({
					title: '登录',
					content: '登录后可使用完整功能',
					cancelText: "取消", // 取消按钮的文字  
					confirmText: "确认", // 确认按钮的文字  
					showCancel: true, // 是否显示取消按钮，默认为 true
					success: (res) => {
						uni.setStorageSync('isModule' , false)
					if(res.confirm) {  
						uni.navigateTo({
							url:'/pages/login/login'
						})
					} else {  
						uni.switchTab({
							url:'/pages/index/index'
						})
						}  
					} 
				})

			}
			
		},
		methods: {
			onlogOut(){
				uni.showModal({
				    title: '提示',
				    content: '是否确认退出登录?',
				    success: function (res) {
				        if (res.confirm) {
				           uni.setStorageSync('token' , '')
						   // window.location.replace('https://qiudaoyu.xikawa.net/')
				           uni.switchTab({
				           	url:'/pages/index/index'
				           })
				        }
				    }
				});
				
			},
			customer(){
				var data = {
					uid:this.uid
				}
				this.$wqzApi.UserDealer_customer(data).then(res=>{
					uni.showToast({
						title:`已绑定为客户`,
						icon:'none'
					})
					uni.setStorageSync('other_uid', '')
					// uni.switchTab({
					// 	url:'/pages/self/self'
					// })
				}).catch(err=>{
					uni.setStorageSync('other_uid', '')
					uni.switchTab({
						url:'/pages/self/self'
					})
				})
			},
			toast_shenqing(){
				uni.showModal({
					title: '提示',
					content: '复制链接后打开浏览器,进行通关号申请',
					cancelText: "取消", // 取消按钮的文字  
					confirmText: "复制", // 确认按钮的文字  
					showCancel: true, // 是否显示取消按钮，默认为 true
					success: (res) => {
					if(res.confirm) {  
						uni.setClipboardData({
							data: 'https://unipass.customs.go.kr/csp/persIndex.do',
							success: function(t) {
								uni.showToast({
								    title: '复制成功',
								    //将值设置为 success 或者直接不用写icon这个参数
								    icon: 'success',
								    //显示持续时间为 2秒
								    duration: 2000
								})
							}
						});
					} else {}  
					} 
				})
			},
			choosekor(type){
				uni.setStorageSync('kor_type' , type)
				this.type_choose = false
				this.kor_type = type
				this.getInfo()
			},
			logOut(){
				uni.showModal({
					title: '退出登录',
					content: '确认退出登录?',
					cancelText: "取消", // 取消按钮的文字  
					confirmText: "确认", // 确认按钮的文字  
					showCancel: true, // 是否显示取消按钮，默认为 true
					success: (res) => {
					if(res.confirm) {  
						this.$wqzApi.login_logout({}).then(res=>{
							for(var key in this.userInfo){
								 this.userInfo[key] = ''
							}
							uni.setStorageSync('token' , '')
							uni.switchTab({
								url:'/pages/index/index'
							})
						})
					} else {}  
					} 
				})
			},
			goUserInfo(){
				if(uni.getStorageSync('token')){
					uni.navigateTo({
						url:'/pages/userInfo/userInfo'
					})
				}else{
					uni.setStorageSync('isModule' , true)
					uni.showModal({
						title: '登录',
						content: '登录后可使用完整功能',
						cancelText: "取消", // 取消按钮的文字  
						confirmText: "确认", // 确认按钮的文字  
						showCancel: true, // 是否显示取消按钮，默认为 true
						success: (res) => {
							uni.setStorageSync('isModule' , true)
						if(res.confirm) {  
							uni.navigateTo({
								url:'/pages/login/login'
							})
						} else {  
							uni.switchTab({
								url:'/pages/index/index'
							})
							}  
						} 
					})
				}
			},
			getInfo(){
				var data = {}
				this.$wqzApi.user_index(data).then(res=>{
					this.userInfo = res.data
					uni.setStorageSync('user_info' , res.data)
					this.barList[0].num = res.data.unpay_num //待支付
					this.barList[1].num = res.data.wait_send_num //待发货
					this.barList[2].num = res.data.sended_num //已发货
					this.barList_buy[0].num = res.data.buy_unexamine //待审核
					this.barList_buy[1].num = res.data.buy_unpay //待支付
					this.barList_buy[2].num = res.data.buy_untreat //待处理
					this.barList_buy[3].num = res.data.buy_treated //已处理
					this.barList_buy[4].num = res.data.buy_store //已入库
					if(res.data.perfect==0){
						uni.showModal({	
						    title: '提示',
						    content: '您还没有完善个人信息,请完善个人信息',
						    success: function (res) {
						        if (res.confirm) {
						            uni.navigateTo({
						            	url:'/pages/userInfo/userInfo'
						            })
						        } else if (res.cancel) {
									uni.redirectTo({
										url:'/pages/index/index'
									})
						        }
						    }
						});
					}
				})
			},
			navTo(url){
				uni.navigateTo({
					url:url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import url(./index.scss);
</style>
